#include "stdafx.h"
#include "qsystray.h"


using namespace micro::gui;


QSysTray::QSysTray( void )
{

    m_bTray = false;

}


QSysTray::~QSysTray( void )
{
    DeleteFromTray();
}

bool QSysTray::IsOnTry()
{
	return m_bTray;
}

void QSysTray::Init( HWND hwnd, UINT msg, UINT id, LPCTSTR str, UINT idIcon, UINT flags )
{
	///systray initialize
	m_nidTray.cbSize = sizeof( NOTIFYICONDATA );
	m_nidTray.hWnd = hwnd;
	_tcscpy_s( m_nidTray.szTip , _countof( m_nidTray.szTip ),  str );

	m_nidTray.hIcon = ::LoadIcon( GetModuleHandle( 0 ), MAKEINTRESOURCE( idIcon ) );
	m_nidTray.uCallbackMessage = msg;

	m_nidTray.uID = id;//pentru identificare
	m_nidTray.uFlags = 	flags ;
	//| NIF_INFO | NIF_SHOWTIP
}

void QSysTray::EnterToTry()
{ 
    ::ShowWindow( m_nidTray.hWnd, SW_HIDE );  

    Shell_NotifyIcon( NIM_ADD, &m_nidTray );
    m_bTray = true;
}

void QSysTray::ExitFromTry()
{
   ::ShowWindow(  m_nidTray.hWnd, SW_SHOW); //activate

    Shell_NotifyIcon( NIM_DELETE, &m_nidTray );
    m_bTray = false;
}

void QSysTray::DeleteFromTray( void )
{
    if ( m_bTray )
    {
        Shell_NotifyIcon( NIM_DELETE, &m_nidTray );
        m_bTray = false;

    }
}
